<template>
  <div class="list-table">
    <div class="nospecialModel ">
      <div v-if="isTitle" class="area-header">
        <span class="area-header-title">{{ $t('融资历史(外部数据)') }}</span>
      </div>
      <el-form ref="queryForm" :model="queryParams" :inline="true">
        <el-form-item :label="$t('披露日期')" prop="financingTime">
          <DatePicker v-model="financingTimes" type="daterange" />
        </el-form-item>
        <el-form-item :label="$t('投资方')" prop="investor">
          <el-input
            v-model="queryParams.investor"
            :placeholder="$t('投资方')"
            clearable
            @keyup.enter.native="queryHandle"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
        </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            v-hasPermi="['company:financeTyc:edit']"
            type="primary"
            icon="el-icon-plus"
            size="mini"
            @click="addHandle"
          >{{ $t('新增') }}</el-button>
        </el-col>
      </el-row>
    </div>
    <div class="specialModel">
      <!-- 不可删除 -->
      <div class="area-header left">
        <span class="area-header-title">{{ $t('融资历史') }}</span>
      </div>
      <div v-if="sourceType !== 'bussRisk'" class="right">
        <el-button
          v-hasPermi="['company:financeTyc:edit']"
          icon="el-icon-plus"
          size="mini"
          type="primary"
          @click="addHandle"
        >{{ $t("新增") }}</el-button>
      </div>
    </div>

    <el-table v-loading="loading" :data="companyFinanceTycList" border tooltip-effect="darkTable">
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <!-- <el-table-column :label="$t('融资日期')" align="center" prop="financingTime" width="180">
        <template slot-scope="scope">
          <span class="link-type" @click="updateHandle(scope.row)">{{ parseTime(scope.row.financingTime) }}</span>
        </template>
      </el-table-column> -->
      <el-table-column :label="$t('披露日期')" align="center" prop="disclosureTime" width="180">
        <template slot-scope="scope">
          <span class="link-type" @click="updateHandle(scope.row)">{{ parseTime(scope.row.disclosureTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('投资方')" align="center" prop="investor" width="200" show-overflow-tooltip />
      <el-table-column :label="$t('交易金额')" align="center" prop="transactionAmount">
        <template slot-scope="scope">
          <span>{{ scope.row.transactionAmount }}</span>
        </template>
      </el-table-column>
      <!--      <el-table-column :label="$t('交易金额') + $t('金额单位')" align="center" prop="transactionAmount" />-->
      <el-table-column :label="$t('融资轮次')" align="center" prop="rounds" />
      <el-table-column :label="$t('投资比例(%)')" align="center" prop="investmentRatio" />
      <el-table-column :label="$t('估值')" align="center" prop="valuation">
        <template slot-scope="scope">
          <span>{{ scope.row.valuation }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('新闻来源')" align="center" prop="newsTitle">
        <template slot-scope="scope">
          <el-link v-if="scope.row.newsUrl" type="primary" @click="findURL(scope.row.newsUrl)">
            {{ scope.row.newsTitle }}
          </el-link>
          <span v-else>
            {{ scope.row.newsTitle }}
          </span>
        </template>
      </el-table-column>
      <el-table-column v-if="sourceType !== 'bussRisk'" :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['company:financeTyc:edit']"
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="updateHandle(scope.row)"
          >{{ $t('修改') }}</el-button>
          <el-button
            v-hasPermi="['company:financeTyc:remove']"
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="deleteHandle(scope.row)"
          >{{ $t('删除') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改【融资历史(外部数据)】对话框 -->
    <el-dialog :title="$t(title)" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <companyFinanceTycForm ref="companyFinanceTycForm" :source-type="sourceType" />
    </el-dialog>
  </div>
</template>

<script>

import { listCompanyFinanceTyc, delCompanyFinanceTyc } from '@/api/company/finance/companyFinanceTyc'
import companyFinanceTycForm from './companyFinanceTycForm.vue'
export default {
    components: {
        companyFinanceTycForm
    },
  props: {
    isTitle: {
      type: Boolean,
      default: true
    },
    sourceType: {
      type: String,
      default: ''
    }
  },
  data() {
      return {
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 融资历史(外部数据)表格数据
          companyFinanceTycList: [],
          // 弹出层标题
          title: '融资历史(外部数据)',
          // 是否显示弹出层
          formOpen: false,
          // 融资时间 参数
          financingTimes: [],
          // 查询参数
          queryParams: {
              companyId: this.$route.query.companyId,
              financingTime: undefined,
              disclosureTime: undefined,
              investor: undefined,
              transactionAmount: undefined,
              investmentRatio: undefined,
              rounds: undefined,
              valuation: undefined,
              newsTitle: undefined,
              newsUrl: undefined,
              pageNum: 1,
              pageSize: 10
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {}
      }
  },
  created() {
      this.getList()
  },
  methods: {
    // 查询【融资历史(外部数据)列表
    getList() {
        this.loading = true
        // 时间参数赋值
        if (this.financingTimes != null && this.financingTimes.length > 1) {
          this.queryParams.startDate = this.financingTimes[0]
          this.queryParams.endDate = this.financingTimes[1]
        } else {
          this.queryParams.startDate = undefined
          this.queryParams.endDate = undefined
        }
        listCompanyFinanceTyc(this.queryParams).then(response => {
            this.companyFinanceTycList = response.rows
            this.total = response.total
            this.loading = false
        })
    },

    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            companyId: undefined,
            financingTime: undefined,
            disclosureTime: undefined,
            investor: undefined,
            transactionAmount: undefined,
            investmentRatio: undefined,
            rounds: undefined,
            valuation: undefined,
            newsTitle: undefined,
            newsUrl: undefined,
            createBy: undefined,
            createTime: undefined,
            updateBy: undefined,
            updateTime: undefined,
            delFlag: undefined
        }
        this.resetForm('form')
    },
    // 搜索按钮操作
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    // 重置按钮操作
    resetQuery() {
        this.resetForm('queryForm')
        this.financingTimes = []
      this.queryHandle()
    },
    // 新增按钮操作
    addHandle() {
        this.formOpen = true
        this.$nextTick(() => {
            this.$refs.companyFinanceTycForm.init(null)
        })
    },
    // 修改按钮操作
    updateHandle(row) {
        this.formOpen = true
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            this.$refs.companyFinanceTycForm.init(row)
        })
    },
    // 删除按钮操作
    deleteHandle(row) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(() => {
            return delCompanyFinanceTyc(row.id)
        }).then(() => {
            this.getList()
            this.msgSuccess(this.$t('删除成功'))
        }).catch(() => {
        })
    },
    // 跳转外部链接
    findURL(url) {
      window.open(url, '_blank')
    }
  }
}
</script>
